/**
 * test
 */
require(["jquery","qzz.querygrid","qzz.grid"],
	function($){   

	var	grid = $("#dataTable").qzzquerygrid({ 
		"height":400,
		"pager":true,
		"colNames":["项目名","流程名","处理人","优先级","是否展示"],   
		"colModels":[   
			{"name":"a",'link':true},        
			{"name":"b",'groups':true}, 
			{"name":"c"},
			{"name":"d"},
			{"name":"e","editType":"onoff","align":"center"}
		]      
	});  	  
    //设置id名称转换列表
    grid.setTransIDName('d',{'1':'高','2':'中','3':'低'});
	grid.value([{"a":"项目1","b":"流程1","c":"处理人1","d":"1","e":"1"},
	            {"a":"项目2","b":"流程2","c":"处理人2","d":"2","e":"1"},
                {"a":"项目3","b":"流程2","c":"处理人3","d":"2","e":"1"},
                {"a":"项目4","b":"流程4","c":"处理人4","d":"3","e":"0"}
            ]);  
	//分页数据
	grid.bind('onPageChanged',function(pageCount, pageSize, pageIndex){
		console.log(pageSize, pageIndex);
		//此处可以是跟据pageSize, pageIndex 从服务端取回的分页数据包。
		grid.value([{"a":"项目5","b":"流程1","c":"处理人1","d":"1"},
			{"a":"项目6","b":"流程2","c":"处理人2","d":"2"},
			{"a":"项目7","b":"流程2","c":"处理人3","d":"2"},
			{"a":"项目8","b":"流程4","c":"处理人4","d":"3"}
		]);  
	});  
	//先配置列属性link:true, 再绑定链接事件，
	 grid.bind('onLinkClick', function(grd, fieldName, node) {
		 console.log(grid.getValue(fieldName));
	 });
     //格式化列数据onFormat后面加_字段名
     grid.dataSet.bind('onFormat_b', function(node, fieldName, dataType, value, metaItem){
		if(this.getValue(fieldName) === "流程4") {
				return '定制流程';
		 } else {
			   return value;
		 }
    });
    //绑定draw事件
    grid.bind('onCellDraw_a', function(dataSet, fieldName, cell) {
	  if(dataSet.getValue(fieldName) == '项目7') {
		  cell.style.color = '#FF0000';
		  cell.style.backgroundColor = '#00FF00';
	  } else {
		  cell.style.color = '';
		  cell.style.backgroundColor = '';
	  }
    });

	grid.setFocus();
	grid.first(); 			
	grid.setTotalRecord(12);  

	var grid = $('#mulTitle').qzzquerygrid({
		  "height":400,
		  'colNames':[
							[{'caption':'日期','startIndex':2,'colSpan':2},{'caption':'贷款信息','startIndex':4,'colSpan':5}],
							['对象名称','统计编码','开始日期','结束日期','贷款来源','金额','内容','默认','停用']
						],
		   'colModels':[
							{'name':'dxmc','frozen':true},
							{'name':'TJBM'},
							{'name':'KSRQ','dataType':'date'},
							{'name':'JSRQ','dataType':'date','showTime':true,'width':150},
							{'name':'DKLY'},
							{'name':'JE', 'scale':2,'sum':true, 'dataType':'number'},
							{'name':'CONTEXT','length':100},
							{'name':'DEFAULT','align':'center'},
							{'name':'STOP','editType':'checkBox','align':'center'}
						]
	  });
	  //初始化数据
	  grid.value([{'dxmc':'1','TJBM':'001','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设'},
				  {'dxmc':'2','TJBM':'002','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','DEFAULT':true},
				  {'dxmc':'21','TJBM':'002001','DKLY':'农业银行','JE':10000,'KSRQ':'2015-10-10'},
				  {'dxmc':'22','TJBM':'002002','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10:09:14:00','STOP':true},
				  {'dxmc':'221','TJBM':'002002001','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
				  {'dxmc':'3','TJBM':'003','DKLY':'交通银行','JE':10000},
				  {'dxmc':'4','TJBM':'004','DKLY':'工商银行','JE':10000,'CONTEXT':'房地产建设'}
				  ]);

      var editGrid = $("#editTable").qzzgrid({ 
          'treeId':'TJBM',
          "height":400,
          'multiselect':true,
          'footerrow':true,
          'colNames':['对象名称','统计编码','开始日期','结束日期','贷款来源','数量','金额','内容','停用','停用2','默认'],
          'colModels':[
                       {'name':'dxmc','frozen':true},
                       {'name':'TJBM'},
                       {'name':'KSRQ','editType':'date'},
                       {'name':'JSRQ','editType':'date','showTime':true,'width':150},
                       {'name':'DKLY','editType':'comboBox',
                                'data':[{'id':'0','text':'农业银行'},
                                        {'id':'1','text':'商业银行'},
                                        {'id':'2','text':'工商银行'},
                                        {'id':'3','text':'交通银行'}
                                        ]},
                       {'name':'SL','editType':'updown', 'minValue':0},
                       {'name':'JE','editType':'number','scale':2, 'dataType':'number','sum':true},
                       {'name':'CONTEXT','length':100,'editType':'buttonEdit'},
                       {'name':'STOP','editType':'checkBox','align':'center'},
                       {'name':'STOP','editType':'onoff','align':'center'},
                       {'name':'DEFAULT','editType':'radio','align':'center'}
                  ]
          });
	   editGrid.value([{'dxmc':'明细1'}, {'dxmc':'明细2'}]);
	   
	   editGrid.bind('onButtonEdit', function(input, fieldName, dataType){
		   alert(this.dataSet.getIndex()+fieldName);
	   }); 

     var treeGrid = $('#treeTable').qzzquerygrid({         
           'treeGrid':true,        
           'idkey':'id',          
           'pidkey':'pid',
           'height':400,          
           'shrinkToFit':true,          
           'multiselect':false,          
           'footerrow':true,          
           'colNames':['对象名称','统计编码','开始日期','结束日期','贷款来源','金额','内容','默认','停用'],          
           'colModels':[                       
                        {'name':'dxmc','frozen':true},                       
                        {'name':'id','dataType':'number'},
                        {'name':'KSRQ','editType':'date'},                       
                        {'name':'JSRQ','editType':'date','showTime':true,'width':150},                       
                        {'name':'DKLY','editType':'comboBox',                                
                                      'data':[{'id':0,'text':'农业银行'},                                        
                                              {'id':'1','text':'商业银行'},                                        
                                              {'id':'2','text':'工商银行'},                                        
                                              {'id':'3','text':'交通银行'}                                        
                                             ]},                       
                        {'name':'JE','editType':'number','scale':2, 'dataType':'number','sum':true},                       
                        {'name':'CONTEXT','length':100},                       
                        {'name':'DEFAULT','editType':'radio','align':'center'},                       
                        {'name':'STOP','editType':'checkBox','align':'center'}                       
                       ]      
      });       
      treeGrid.value([{'dxmc':'1','id':1,'pid':0,'DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'2','id':2,'pid':0,'DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','DEFAULT':true},
                 {'dxmc':'21','id':3,'pid':2,'DKLY':'农业银行','JE':10000,'KSRQ':'2015-10-10'},
                 {'dxmc':'22','id':4,'pid':2,'DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'124','id':5,'pid':4,'DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'3','id':6,'pid':0,'DKLY':'交通银行','JE':10001},
                 {'dxmc':'4','id':7,'pid':0,'DKLY':'工商银行','JE':10000,'CONTEXT':'社区建设费'},
                 {'dxmc':'4','id':8,'pid':0,'DKLY':'工商银行','JE':10000,'CONTEXT':'房地产建设'}]); 

     var treeGrid2 = $('#treeTable2').qzzquerygrid({          
           'treeGrid':true,          
           'idkey':'TJBM',          
           'height':400,          
           'shrinkToFit':true,          
           'multiselect':true,          
           isExpanded:false, // 默认不展开树节点
           'footerrow':true,          
           'colNames':['对象名称','统计编码','开始日期','结束日期','贷款来源','金额','内容','默认','停用'],          
           'colModels':[                       
                        {'name':'dxmc','frozen':true},                       
                        {'name':'TJBM'},
                        {'name':'KSRQ','editType':'date'},                       
                        {'name':'JSRQ','editType':'date','showTime':true,'width':150},                       
                        {'name':'DKLY','editType':'comboBox',                                
                                      'data':[{'id':0,'text':'农业银行'},                                        
                                              {'id':'1','text':'商业银行'},                                        
                                              {'id':'2','text':'工商银行'},                                        
                                              {'id':'3','text':'交通银行'}                                        
                                             ]},                       
                        {'name':'JE','editType':'number','scale':2, 'dataType':'number','sum':true},                       
                        {'name':'CONTEXT','length':100},                       
                        {'name':'DEFAULT','editType':'radio','align':'center'},                       
                        {'name':'STOP','editType':'checkBox','align':'center'}                       
                       ]      
      });       
      treeGrid2.value([{'dxmc':'1','TJBM':'001','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'2','TJBM':'002','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','DEFAULT':true},
                 {'dxmc':'21','TJBM':'002001','DKLY':'农业银行','JE':10000,'KSRQ':'2015-10-10'},
                 {'dxmc':'22','TJBM':'002002','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'221','TJBM':'002002001','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'222','TJBM':'002002002','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'223','TJBM':'002002003','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'224','TJBM':'002002004','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'225','TJBM':'002002005','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'226','TJBM':'002002006','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'227','TJBM':'002002007','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'228','TJBM':'002002008','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','STOP':true},
                 {'dxmc':'23','TJBM':'002003','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'24','TJBM':'002004','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'25','TJBM':'002005','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'26','TJBM':'002006','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'27','TJBM':'002007','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'28','TJBM':'002008','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'29','TJBM':'002009','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'210','TJBM':'002010','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'211','TJBM':'002011','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'212','TJBM':'002012','DKLY':'农业银行','JE':10000,'CONTEXT':'房地产建设','JSRQ':'2015-10-10 09:14:00','STOP':true},
                 {'dxmc':'3','TJBM':'003','DKLY':'交通银行','JE':10001},
                 {'dxmc':'4','TJBM':'004','DKLY':'工商银行','JE':10000,'CON':'3','TJBM':'003','DKLY':'交通银行','JE':10001},
                 {'dxmc':'4','TJBM':'004','DKLY':'工商银行','JE':10000,'CONTEXT':'房地产建设'}]); 
 


});

